package com.tianma.upload.uploadjartest.socket.demo02;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author lgc
 * @createDate 2020/8/17 - 13:40
 */
public class SocketTest02 {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8888);
        OutputStream outputStream = socket.getOutputStream();
        FileInputStream fis = new FileInputStream("F:\\测试图片\\1.jpg");

        byte[] bytes = new byte[1024];
        int i;
       while((i= fis.read(bytes))!=-1){
           outputStream.write(bytes,0,i);
       }
       socket.shutdownOutput();

        InputStream inputStream = socket.getInputStream();
        byte[] bytes2 = new byte[1024];
        int read = inputStream.read(bytes2);
        System.out.println(new String(bytes2,0,read));

        inputStream.close();
        fis.close();
        outputStream.close();
        socket.close();
    }
}
